//
//  CNCollectStatusViewModel.m
//  BBSModule
//
//  Created by 邓建东 on 2020/5/19.
//  Copyright © 2020 dong. All rights reserved.
//

#import "CNCollectStatusViewModel.h"
#import "CNCollectionNetManager.h"
#import <YYModel/YYModel.h>
@implementation CNCollectStatusViewModel


// 查询是否收藏
- (void)checkFavoriteWithUrl:(NSString *)url source:(NSString *)source completionHandle:(CompletionHandle)completionHandle{
    self.dataTask = [CNCollectionNetManager checkFavoriteWithUrl:url source:source completionHandle:^(id response, NSError *error) {
        if (!error) {
            self.code = [response[@"code"] integerValue];
            self.message = response[@"msg"];
            if (self.code == 200) {
                [self.dataArr removeAllObjects];
                
                NSArray *array = [NSArray  yy_modelArrayWithClass:[CNMineCollectFoldersModel class] json:response[@"data"]]; 
                [self.dataArr addObjectsFromArray:array];
            }
        }
        completionHandle(error);
    }];
}

/// 单条取消收藏
- (void)delFavoriteWithFavoritedId:(NSString *)FavoritedId  completionHandle:(CompletionHandle)completionHandle{
    self.dataTask = [CNCollectionNetManager delFavoriteWithFavoritedId:FavoritedId completionHandle:^(id response, NSError *error) { 
        if (!error) {
            self.code = [response[@"code"] integerValue];
            self.message = response[@"msg"];
        }
        completionHandle(error);
    }];
}

/// 单条添加收藏
- (void)addFavoriteWithFolderId:(NSString *)folderId collectionModel:(CNMineNewCollectModel *)collectModel completionHandle:(CompletionHandle)completionHandle{
    self.dataTask = [CNCollectionNetManager addFavoriteWithFolderId:folderId collectionModel:collectModel completionHandle:^(id response, NSError *error) {
        if (!error) { 
            self.code = [response[@"code"] integerValue];
            self.message = response[@"msg"];
        }
        completionHandle(error);

    }];
}

- (void)editFolderWithFolderId:(NSString *)folderId folderName:(NSString *)folderName desc:(NSString *)desc isPrivate:(BOOL)isPrivate completionHandle:(CompletionHandle)completionHandle{
    self.dataTask = [CNCollectionNetManager editFolderWithFolderId:folderId folderName:folderName desc:desc isPrivate:isPrivate completionHandle:^(id response, NSError *error) {
        if (!error) {
            self.code = [response[@"code"] integerValue];
            self.message = response[@"msg"];
        }
        completionHandle(error);
    }];
}

// 添加删除编辑收藏夹
- (void)addFolderWithFolderName:(NSString *)folderName desc:(NSString *)desc isPrivate:(BOOL)isPrivate completionHandle:(CompletionHandle)completionHandle {
    self.dataTask = [CNCollectionNetManager addFolderWithFolderName:folderName desc:desc isPrivate:isPrivate completionHandle:^(id response, NSError *error) { 
        if (!error) {
            self.code = [response[@"code"] integerValue];
            self.message = response[@"msg"];
            if (self.code == 200) {
                self.editFolderModel = [CNMineCollectFoldersModel yy_modelWithJSON:response[@"data"]];
            }
        }
        completionHandle(error);
    }];
}
@end
